<template>
  <div class="page" :style="{backgroundImage:`url(${bgList[bgIndex]})`}">
    <m-header
      title=""
      :canback="Boolean(1)"
      :nobg="true"
    ></m-header>
    <section class="body">
      <div class="img-box">
        <!-- <img class="logo" :src="logoSrc" alt=""> -->
        <!-- <p class="tips">长按屏幕识别二维码</p> -->
        <div class="bg-list">
          <img :src="item" :class="{active:index===bgIndex}" v-for="(item,index) in bgList" :key="index" @click="bgIndex=index" alt="">
        </div>
        <div :class="`content class1`">
          <img
            class="img"
            style="margin-top: 5px;"
            :src="inviteSrc"
            alt
          />
          <p class="code">推荐ID：{{userInfo&&userInfo.id}}</p>
        </div>
        <!-- <p class="tip"><i>盤</i> <img class="money-img" :src="moneySrc" alt=""> <i>他</i> </p> -->
        <!-- <p v-if="userInfo" class="url">{{inviteUrl}}</p> -->
        <!-- <input class="inp_url" type="text" id="url" :value="inviteUrl" readonly /> -->
        <!-- <button ref="copy" class="btn btn-copy" data-clipboard-target="#url" data-clipboard-action="copy" @click="copy">復制</button> -->
      </div>
    </section>
  </div>
</template>
<script>
import QRCode from 'qrcode';
import { mapGetters } from 'vuex';
import Clipboard from 'clipboard';
import { Util } from '@/assets/commonjs/utils.js'
export default {
  name: "invite",
  data() {
    return {
      inviteSrc: null,
      inviteUrl: null,
      myClipboard: null,
      logoSrc: require('@/assets/images/invite_logo.png'),
      moneySrc: require('@/assets/images/money.png'),
      bgList:[require('@/assets/images/customer1.jpg'),require('@/assets/images/customer2.jpg')],
      bgIndex:1
    }
  },
  mounted() {
    // console.log(this.userInfo)
    this.initData();
    this.setCode(this.inviteUrl);
    // this.myClipboard = new Clipboard(this.$refs['copy']);
  },
  computed: {
    ...mapGetters(['uid', 'userInfo', 'api',])
  },
  methods: {
    initData() {
      this.inviteUrl = this.api + '/dist/index.html#' + '/register?id=' + this.uid;
    },
    setCode(url) {
      QRCode.toDataURL(url).then(url => {
        this.inviteSrc = url;
      })
        .catch(err => {
          console.error(err)
        })
    },
    copy() {
      this.myClipboard.on('success', (e) => {
        mui.toast('復制成功！');
      })
      this.myClipboard.on('error', (e) => {
        Util.commonCopy('url');
      })
    }
  }
}
</script>
<style lang="less" scoped>
@import "~link-less";
.page {
  // background-image: url("../../../assets/images/customer.png");

  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
}
.body {
  background: transparent;
  background-color: transparent;
  text-align: center;
  //   border-top: 1px solid rgba(255, 255, 255, 0.3);
  position: relative;
  .bg-list {
    display: flex;
    flex-direction: column;
    width: 150px;
    position: absolute;
    right: 10px;
    bottom: 50px;
    height: 330px;
    overflow-y: auto;
    box-shadow: 0 0 20px 10px #eeeeee;
    img {
      width: 150px;
      &.active {
        border: 4px solid #F0E68C;
        box-sizing: border-box;
      }
    }
  }
  .title {
    font-size: 40px;
    color: @primary-color;
    margin-top: 5%;
  }
  .url {
    // margin-top: 75%;
    padding: 0 20px;
    margin-bottom: 20px;
    color: #333;
    word-break: break-all;
    user-select: text;
    -webkit-user-select: text;
  }
  .inp_url {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
  }
  .img-box {
    // position: absolute;
    // // top: 0;
    // left: 20px;
    // bottom: 30px;
    // // height: 760px;
    // width: 50%;
    // // background-color: white;
    // border-radius: 10px;
    // padding: 100px 0 0 0;
    // width: 100%;
    // height: 100%;
    // top: 0;
    // left: 0;
    // bottom: 0;
    // right: 0;
    .content {
      position: absolute;
      left: 50%;
      &.class0 { bottom: 26%;}
      &.class1 { bottom: 42%;}
      transform: translateX(-50%);
      .code {
        background-color: #fff;
        color: black;
        font-size: 12px;
        margin-top: -15px;
      }
    }
    .tips {
      color: #fff;
      font-size: 10px;
      display: inline-block;
      padding: 5px 10px;
      border-radius: 10px;
      background: #00ad9c;
      margin-top: 90px;
    }
    .img {
      width: 250px;
      margin-top: 150px;
      display: block;
    }
    .money-img {
      width: 40px;
    }
    // .transform(translateX(-50%));
    .tip {
      color: @primary-color;
      // margin-top: 77px;
    }
    .btn-copy {
      background-color: @btn-primary-color;
      font-size: 28px;
    }
    .logo {
      position: absolute;
      top: -16%;
      left: 50%;
      .transform(translateX(-50%));
      height: 200px;
    }
  }
  //   @media screen and (max-height: 667px) {
  //     .img-box {
  //       position: absolute;
  //       bottom: 10%;
  //       left: 50%;
  //       .transform(translateX(-50%));
  //     }
  //   }
}
</style>
